const express = require("express");
const morgan = require("morgan");
const UserRouter = require("./routes/UserRouter")
const ToolsRouter = require("./routes/ToolsRouter")
const SystemRouter = require("./routes/SystemRouter")
const DoctorRouter = require("./routes/DoctorRouter")
const ContractRouter = require("./routes/ContractRouter")

const app = express();

app.use(morgan("dev"));
//CORS配置
app.all("*", function (req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header(
    "Access-Control-Allow-Headers",
    "Content-Type,Content-Length, Authorization, Accept,X-Requested-With"
  );
  res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
  res.header("X-Powered-By", " 3.2.1");
  if (req.method == "OPTIONS") res.send(200);
  /*让options请求快速返回*/
  else next();
});

app.use(express.urlencoded({limit:'10mb', extended: true }));
app.use(express.json({limit:'10mb'}));
app.use(express.static(__dirname + "/public"));

// 路由
app.use('/api',UserRouter);
app.use('/api',ToolsRouter);
app.use('/api',SystemRouter);
app.use('/api',DoctorRouter);
app.use('/api',ContractRouter);

app.set("port", 1111);
app.listen(app.get("port"), () => {
  console.log(`请通过 http://127.0.0.1:${app.get("port")} 访问页面`);
  // console.log(`http://172.16.8.22:${app.get("port")}`);
});
